package com.example.a10928.weifriend.ui.personal_center

import android.content.Intent
import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.widget.LinearLayoutManager
import android.text.TextUtils
import android.util.Log
import android.widget.AdapterView
import com.example.a10928.weifriend.App
import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.adapter.MyTeamAdapter
import com.example.a10928.weifriend.adapter.MyWalletAdapter
import com.example.a10928.weifriend.http.api.VariableName
import com.example.a10928.weifriend.http.api.base.VIPBean
import com.example.a10928.weifriend.ui.BaseActivity
import com.example.a10928.weifriend.util.RxUtil
import com.example.a10928.weifriend.util.StatusBarUtil
import com.githang.statusbar.StatusBarCompat
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_my_team.*
import java.util.ArrayList

class MyTeamActivity : BaseActivity() {


    var datas = ArrayList<VIPBean>()
    var adapter:MyTeamAdapter?=null
    var type:String?=null

    override fun getContentView(): Int {
        return R.layout.activity_my_team
    }

    override fun initView() {
        StatusBarCompat.setStatusBarColor(this, Color.WHITE,true)
        supportActionBar?.hide()
        type=  intent.getStringExtra("type")


        adapter = MyTeamAdapter(R.layout.item_my_team, datas,type,layout_title)
        recyc.setLayoutManager(LinearLayoutManager(this))
        recyc.setAdapter(adapter)

        if(TextUtils.isEmpty(type)){
            adapter?.setOnItemClickListener { adapter, view, position ->
                var myIntent= Intent(this,MyTeamActivity::class.java)
                myIntent.putExtra("type",""+position)
                startActivity(myIntent)
                Log.v("zzw","team one")
            }
        }else{
            adapter?.setOnItemClickListener { adapter, view, position ->

               // if(type.equals("0")){
                    var myIntent= Intent(this,MemberActivity::class.java)
                    myIntent.putExtra(VariableName.TWOTYPE,type)
                    if(datas.get(position).name.equals("普通会员")){
                        myIntent.putExtra(VariableName.TYPE,""+1)

                    }else{
                        myIntent.putExtra(VariableName.TYPE,""+2)
                    }
                    startActivity(myIntent)
/*                }else{

                }*/

            }
        }

        if(TextUtils.isEmpty(type)){
            App.app().bpService.getSonsNum(App.app().user.userId)
                    .compose(RxUtil.io2mainLoad(this))
                    .subscribe(
                            Consumer {
                                var one=VIPBean()
                                one.num=it.data.class1
                                one.name="一级会员"
                                var two=VIPBean()
                                two.num=it.data.class2
                                two.name="二级会员"

                                datas.add(one)
                                datas.add(two)

                                adapter?.notifyDataSetChanged()


                            },
                            Consumer {
                                RxUtil.errorException(it)
                            }
                    )
        }else if(type.equals("0")){


            App.app().bpService.getClass1Num(App.app().user.userId)
                    .compose(RxUtil.io2mainLoad(this))
                    .subscribe(
                            Consumer {
                                var one=VIPBean()
                                one.num=it.data.normal_num
                                one.name="普通会员"
                                var two=VIPBean()
                                two.num=it.data.vip_num
                                two.name="VIP会员"

                                datas.add(two)
                                datas.add(one)

                                adapter?.notifyDataSetChanged()
                            },
                            Consumer {
                                RxUtil.errorException(it)
                            }
                    )


        }else{

            App.app().bpService.getClass2Num(App.app().user.userId)
                    .compose(RxUtil.io2mainLoad(this))
                    .subscribe(
                            Consumer {
                                var one=VIPBean()
                                one.num=it.data.normal_num
                                one.name="普通会员"
                                var two=VIPBean()
                                two.num=it.data.vip_num
                                two.name="VIP会员"

                                datas.add(two)
                                datas.add(one)

                                adapter?.notifyDataSetChanged()
                            },
                            Consumer {
                                RxUtil.errorException(it)
                            }
                    )

        }



    }

    override fun initData() {


    }



}
